<template>
  <div>
    <div class="history" v-if="isShowHistory">

      <div class="top">
        <h4>历史记录</h4>
        <span><van-icon name="delete-o" @click="cleanHistory"/>
        </span>
      </div>

      <div class="down">
        <van-tag plain @click="historyTagClick(item)" v-for="(item,index) in historyKeywordList" :key="index">{{ item }}</van-tag>
      </div>
    </div>

    <div class="history">
      <div class="top"><h4>热门搜索</h4></div>
      <div class="down">
        <van-tag plain @click="historyTagClick(item)" v-for="(item,index) in hotKeywordList" :type="item.is_hot == 1? 'danger':'default'" :key="index">{{ item.keyword }}</van-tag>
      </div>
    </div>
  </div>
</template>

<script>
import {cleanHistorySearch} from '@/request/api'
export default {
  name: "HistoryHot",
  data(){
    return {
      isShowHistory:true,
    }
  },
  props:{
    historyKeywordList:{
      type:Array,
      default:[]
    },
    hotKeywordList:{
      type:Array,
      default:[]
    }
  },
  mounted() {

  },
  methods:{
    historyTagClick(item){
      console.log(item)
      this.$emit('historyTagClick',item);
    },
    async cleanHistory(){
      const {data:res} = await cleanHistorySearch();
      if(res.errno == 0){
        this.$toast.success('清除成功')
        this.isShowHistory = false;
        console.log(res)
      }
    }
  }
}
</script>

<style lang="less" scoped>
.history {
  padding: 0 2%;
  background-color: #fff;
  margin-bottom: .2rem;

  .top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    //background-color: pink;
    height: .5rem;
    font-size: .2rem;
    h4 {
      font-weight: normal;
    }
  }



  .down {
      .van-tag {
        font-size: .14rem;
          margin-right: .08rem;
          margin-bottom: .08rem;
        padding: .03rem;
      }
  }
}
</style>